//
//  Puser.m
//  CarTown
//
//  Created by xionghao on 15/9/2.
//  Copyright (c) 2015年 熊浩. All rights reserved.
//

#import "Puser.h"
#import "AppDelegate.h"

@implementation Puser

@dynamic autologin;
@dynamic bindtephone;
@dynamic com_adress;
@dynamic com_book;
@dynamic com_brand;
@dynamic com_ctphone;
@dynamic com_ctusername;
@dynamic com_fren;
@dynamic com_handwith;
@dynamic com_ico;
@dynamic com_id;
@dynamic com_intro;
@dynamic com_job;
@dynamic com_name;
@dynamic com_namef;
@dynamic com_namez;
@dynamic com_password;
@dynamic com_qq;
@dynamic com_regtime;
@dynamic com_renzhen;
@dynamic com_tephone;
@dynamic com_user_id;
@dynamic com_username;
@dynamic com_weixin;
@dynamic com_zhizhao;
@dynamic com_zhizhao1;
@dynamic com_zhizhao2;
@dynamic erp;
@dynamic link;
@dynamic locked;
@dynamic master_lev;
@dynamic master_name;
@dynamic parent_id;
@dynamic power;
@dynamic role_id;
@dynamic session_id;
@dynamic show_pic;
@dynamic show_pic1;
@dynamic show_pic2;
@dynamic show_pic3;
@dynamic show_pic4;
@dynamic uid;
@dynamic user_address;
@dynamic user_birthday;
@dynamic user_card_img;
@dynamic user_city;
@dynamic user_company_address;
@dynamic user_country;
@dynamic user_district;
@dynamic user_gender;
@dynamic user_handwith;
@dynamic user_ico;
@dynamic user_id;
@dynamic user_intro;
@dynamic user_job;
@dynamic user_marry;
@dynamic user_mobile;
@dynamic user_msn;
@dynamic user_nameportf;
@dynamic user_nameportz;
@dynamic user_porttype;
@dynamic user_province;
@dynamic user_qq;
@dynamic user_renzhen;
@dynamic user_renzhen_type;
@dynamic user_report;
@dynamic user_report_handwith;
@dynamic user_report_img;
@dynamic user_savegold;
@dynamic user_skype;
@dynamic user_telphone;
@dynamic user_time;
@dynamic user_truename;
@dynamic user_weixin;
@dynamic user_zipcode;
@dynamic renz;
@dynamic likn;
@dynamic shopinfo;
@dynamic shop_logo;
@dynamic shop_city;
@dynamic shop_district;
@dynamic shop_province;
@dynamic shop_categories;
@dynamic shop_intro;
@dynamic shop_address;
@dynamic atten_count;
@dynamic fav_count;
@dynamic show_pics;
@dynamic shop_men_imgs;
+(void)save{
      AppDelegate *delegate= [[UIApplication sharedApplication] delegate];
    [delegate saveContext];
}
+(instancetype)userWithDict:(NSDictionary *)dict WithPower:(NSNumber *)tpower{
    
    
    AppDelegate *delegate= [[UIApplication sharedApplication] delegate];
    
    NSFetchRequest *request=[NSFetchRequest fetchRequestWithEntityName:@"Puser"];
    NSArray *sets= [delegate.managedObjectContext executeFetchRequest:request error:nil];
    Puser *user;
    if (sets.count>0) {
        user=sets[0];
    }else{
        user=[NSEntityDescription insertNewObjectForEntityForName:@"Puser" inManagedObjectContext:delegate.managedObjectContext];
    }
    if (tpower) {
        user.power=tpower;
    }
    //个人
    
    
    
    [user setValue:dict[@"user_id"] forKey:@"user_id"];
    [user setValue:dict[@"user_truename"] forKey:@"user_truename"];
    [user setValue:dict[@"show_pic"] forKey:@"show_pic"];
    [user setValue:dict[@"show_pics"] forKey:@"show_pics"];
    [user setValue:dict[@"link"] forKey:@"link"];
    [user setValue:dict[@"user_ico"] forKey:@"user_ico"];
    [user setValue:dict[@"user_marry"]forKey:@"user_marry"];
    [user setValue:dict[@"user_gender"] forKey:@"user_gender"];
    [user setValue:dict[@"user_mobile"] forKey:@"user_mobile"];
    [user setValue:dict[@"user_telphone"] forKey:@"user_telphone"];
    [user setValue:dict[@"user_country"] forKey:@"user_country"];
    [user setValue:dict[@"user_province"]forKey:@"user_province"];
    [user setValue:dict[@"user_city"] forKey:@"user_city"];
    [user setValue:dict[@"user_district"] forKey:@"user_district"];
    [user setValue:dict[@"user_zipcode"] forKey:@"user_zipcode"];
    [user setValue:dict[@"user_address"] forKey:@"user_address"];
    [user setValue:dict[@"user_job"] forKey:@"user_job"];
    [user setValue:dict[@"user_company_address"] forKey:@"user_company_address"];
    [user setValue:dict[@"user_card_img"] forKey:@"user_card_img"];
    [user setValue:dict[@"user_birthday"] forKey:@"user_birthday"];
    [user setValue:dict[@"user_qq"] forKey:@"user_qq"];
    [user setValue:dict[@"user_weixin"] forKey:@"user_weixin"];
    [user setValue:dict[@"user_msn"] forKey:@"user_msn"];
    [user setValue:dict[@"user_skype"] forKey:@"user_skype"];
    [user setValue:dict[@"user_porttype"] forKey:@"user_porttype"];
    [user setValue:dict[@"user_report"] forKey:@"user_report"];
    [user setValue:dict[@"user_nameportz"] forKey:@"user_nameportz"];
    [user setValue:dict[@"user_nameportf"] forKey:@"user_nameportf"];
    [user setValue:dict[@"user_savegold"] forKey:@"user_savegold"];
    [user setValue:dict[@"user_renzhen"] forKey:@"user_renzhen"];
    [user setValue:dict[@"user_intro"] forKey:@"user_intro"];
    [user setValue:dict[@"role_id"] forKey:@"role_id"];
    [user setValue:dict[@"user_renzhen_type"] forKey:@"user_renzhen_type"];
    [user setValue:dict[@"user_handwith"] forKey:@"user_handwith"];
    [user setValue:dict[@"user_report_img"] forKey:@"user_report_img"];
    [user setValue:dict[@"user_report_handwith"] forKey:@"user_report_handwith"];
    //公司
    [user setValue:dict[@"com_id"]forKey:@"com_id"];
    [user setValue:dict[@"com_user_id"] forKey:@"com_user_id"];
    [user setValue:dict[@"com_username"] forKey:@"com_username"];
    [user setValue:dict[@"com_name"] forKey:@"com_name"];
    [user setValue:dict[@"com_password"] forKey:@"com_password"];
    [user setValue:dict[@"com_zhizhao"] forKey:@"com_zhizhao"];
    [user setValue:dict[@"com_ctphone"] forKey:@"com_ctphone"];
    [user setValue:dict[@"com_zhizhao1"] forKey:@"com_zhizhao1"];
    [user setValue:dict[@"com_zhizhao2"] forKey:@"com_zhizhao2"];
    [user setValue:dict[@"com_regtime"] forKey:@"com_regtime"];
    [user setValue:dict[@"com_qq"] forKey:@"com_qq"];
    [user setValue:dict[@"com_weixin"] forKey:@"com_weixin"];
    [user setValue:dict[@"com_tephone"] forKey:@"com_tephone"];
    [user setValue:dict[@"com_adress"] forKey:@"com_adress"];
    [user setValue:dict[@"com_intro"]forKey:@"com_intro"];
    [user setValue:dict[@"com_ico"] forKey:@"com_renzhen"];
    [user setValue:dict[@"com_renzhen"] forKey:@"com_renzhen"];
    [user setValue:dict[@"com_fren"] forKey:@"com_fren"];
    [user setValue:dict[@"com_book"] forKey:@"com_book"];
    [user setValue:dict[@"com_namez"] forKey:@"com_namez"];
    [user setValue:dict[@"com_namef"] forKey:@"com_namef"];
    [user setValue:dict[@"com_handwith"] forKey:@"com_handwith"];
    [user setValue:dict[@"com_job"] forKey:@"com_job"];
    [user setValue:dict[@"parent_id"] forKey:@"parent_id"];
    [user setValue:dict[@"locked"] forKey:@"locked"];
    [user setValue:dict[@"master_name"] forKey:@"master_name"];
    [user setValue:dict[@"master_lev"] forKey:@"master_lev"];
    [user setValue:dict[@"bindtephone"] forKey:@"bindtephone"];
    [user setValue:dict[@"com_brand"] forKey:@"com_brand"];
    [user setValue:dict[@"erp"] forKey:@"erp"];
    [user setValue:dict[@"renz"] forKey:@"renz"];
    [user setValue:dict[@"likn"] forKey:@"likn"];
    [user setValue:dict[@"shop_men_imgs"] forKey:@"shop_men_imgs"];
    [user setValue:dict[@"shopinfo"] forKey:@"shopinfo"];
    [user setValue:dict[@"shop_logo"] forKey:@"shop_logo"];
    [user setValue:dict[@"shop_province"] forKey:@"shop_province"];
    [user setValue:dict[@"shop_city"] forKey:@"shop_city"];
    [user setValue:dict[@"shop_district"] forKey:@"shop_district"];
    [user setValue:dict[@"shop_intro"] forKey:@"shop_intro"];
    [user setValue:dict[@"shop_categories"] forKey:@"shop_categories"];
    [user setValue:dict[@"shop_address"] forKey:@"shop_address"];
    [user setValue:dict[@"atten_count"] forKey:@"atten_count"];
    [user setValue:dict[@"fav_count"] forKey:@"fav_count"];
    [delegate saveContext];
    return user;
}

-(void)setValue:(id)value forUndefinedKey:(NSString *)key{
    if ([key isEqualToString:@"id"]) {
        self.uid=value;
    }
}
+(instancetype)getUser{
    AppDelegate *delegate= [[UIApplication sharedApplication] delegate];
    NSFetchRequest *request=[NSFetchRequest fetchRequestWithEntityName:@"Puser"];
    NSArray *sets= [delegate.managedObjectContext executeFetchRequest:request error:nil];
    if (sets.count>0) {
        return sets[0];
    }else{
        return nil;
    }
}



@end
